package com.demo.app.controller.entpr;

import com.demo.app.service.entpr.EntprService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import model.dto.del.BatchDeleteDto;
import model.dto.entpr.InsertEntprDto;
import model.dto.entpr.UpdateEntprDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import result.Result;
import util.SearchFilter;

/**
 * @program: fire_control
 * @description:
 * @author: fbl
 * @create: 2021-04-01 08:58
 **/
@RestController
@Validated
@Api(value = "EntprController", tags = "企业管理")
@RequestMapping("/api/entpr")
public class EntprController {

    @Autowired
    EntprService entprService;

    @PostMapping("/list")
    @PreAuthorize("@ss.hasPer('0038')")
    @ApiOperation(value = "展示企业信息")
    public Result entprList(@RequestBody @Validated SearchFilter searchFilter){
        return  entprService.entprList(searchFilter);
    }

    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPer('0038')")
    @ApiOperation(value = "展示企业详情")
    public Result entprDetail(@PathVariable Integer id){
        return  entprService.entprDetail(id);
    }

    @PutMapping
    @PreAuthorize("@ss.hasPer('0038')")
    @ApiOperation(value = "修改企业信息")
    public Result updateEntpr(@RequestBody @Validated UpdateEntprDto updateEntprDto){
        return entprService.updateEntpr(updateEntprDto);
    }

    @PostMapping
    @PreAuthorize("@ss.hasPer('0038')")
    @ApiOperation(value = "新增企业信息")
    public Result addEntpr(@RequestBody @Validated InsertEntprDto insertEntprDto){
        return entprService.addEntpr(insertEntprDto);
    }

    @PostMapping("/del")
    @PreAuthorize("@ss.hasPer('0038')")
    @ApiOperation(value = "删除企业信息")
    public Result delEntpr(@RequestBody @Validated BatchDeleteDto batchDeleteDto){
        return entprService.delEntpr(batchDeleteDto);
    }
}
